package com.oocl.o2o.merchant.controller.rest;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.SessionAttribute;

import com.oocl.o2o.merchant.entity.Advertisement;
import com.oocl.o2o.merchant.entity.AdvertisementStatus;
import com.oocl.o2o.merchant.entity.Food;
import com.oocl.o2o.merchant.entity.Merchant;
import com.oocl.o2o.merchant.service.AdvertisementManager;

@RestController
@RequestMapping("/sec/rest/advertisement")
public class AdvertisementController {

	@Autowired
	private AdvertisementManager advertisementManager;
	
	@GetMapping
	public List<Advertisement> getMyAdvertisements(@SessionAttribute String merchantId){
		return advertisementManager.findByMerchantId(merchantId);
	}
	
	@PostMapping
	public boolean addAdvertisement(@SessionAttribute String merchantId,String foodId,Double compPrice,String applyReason) {
		Merchant merchant = new Merchant(merchantId, null, null, null, null, null);
		Food food = new Food(foodId, null, null, null, null, null);
		Advertisement ad = new Advertisement(merchant, food, AdvertisementStatus.OFF);
		ad.setCompPrice(compPrice);
		System.out.println(applyReason);
		ad = advertisementManager.sendAdvertisement(ad,applyReason);
		if(ad==null)
			return false;
		return true;
	}
	
}
